package my.test.bean.ex14.config;

import org.springframework.transaction.support.TransactionSynchronizationAdapter;
import org.springframework.transaction.support.TransactionSynchronizationManager;

import my.test.bean.ex14.synchronization.TransactionalMessageSender;

public class ProductService {
   ProductDao productDao;

   public ProductDao getProductDao() {
	  return productDao;
   }

   public void setProductDao(ProductDao productDao) {
	  this.productDao = productDao;
   }
   
   /**
    * 某个用户购买指定商品
    * @param buyerName
    * @param goodsId
    */
   public void sellProduct(String buyerName, String goodsId) {
	  //更新库存 
	  productDao.updateStock(goodsId); 
	  TransactionSynchronizationManager.registerSynchronization(new TransactionalMessageSender());
      //事务测试，加上这句代码则数据不会保存到数据库中
	  throw new RuntimeException("aa");
   }
}
